<?php
class Master_ortuwali extends CI_Model 
{

	function __construct()
	{
		parent::__construct();
	}
	
	function add($dataInsert)
	{
		$query = $this->db->insert('mr_ortuwali', $dataInsert);
		return $query;
	}
	
	function detail($nis)
	{
		$this->db->select('mr_ortuwali.*,mr_pekerjaan.*,mr_gaji.*,mr_pendidikan.*,mr_agama.*,');
		$this->db->from('mr_ortuwali');
		$this->db->join('mr_pekerjaan', 'mr_pekerjaan.id_mr_pekerjaan = mr_ortuwali.id_mr_pekerjaan','left');
		$this->db->join('mr_gaji', 'mr_gaji.id_mr_gaji = mr_ortuwali.id_mr_gaji','left');
		$this->db->join('mr_pendidikan', 'mr_pendidikan.id_mr_pendidikan = mr_ortuwali.id_mr_pendidikan','left');
		$this->db->join('mr_agama', 'mr_agama.id_mr_agama = mr_ortuwali.id_mr_agama','left');
		$this->db->where('mr_ortuwali.nis',$nis);
		$this->db->_protect_identifiers = FALSE;
		$this ->db->order_by('FIELD( hubungan, "Ayah", "Ibu", "Wali" )');
		$this->db->_protect_identifiers = TRUE;

		$query = $this->db->get();		
		return $query->result();
	}
	
	function edit($id_mr_ortuwali)
	{
		$this->db->where('id_mr_ortuwali',$id_mr_ortuwali);
		$query=$this->db->get('mr_ortuwali');
		return $query->result();
	}
	
	function update($id_mr_ortuwali,$dataUpdate)
	{
		$this->db->where('id_mr_ortuwali', $id_mr_ortuwali);
		$update = $this->db->update('mr_ortuwali', $dataUpdate);
		return $update;
	}
	
	function delete($id_mr_ortuwali)
	{
		$this->db->where('id_mr_ortuwali', $id_mr_ortuwali);
		$delete = $this->db->delete('mr_ortuwali');
		return $delete;
	}
	
}